module Trifle
	module Ruby
		class Logger < ::Logger
			def self.error(message)
				build.error(message)
			end

			def self.build
				new(::Rails.root.join("log", file_name))
			end

			def self.info(message)
				build.info(message)
			end

			def self.read_latest
				path = ::Rails.root.join("log", file_name)
				self.build unless File.exist?(path)
				logs = `tail -n 1000 #{path}`.lines
			end

			def self.read_latest_for filename
				path = ::Rails.root.join("log", filename)
				logs = `tail -n 1000 #{path}`.lines
			end

			def self.file_name
				"trifle-ruby.log"
			end

			def format_message(severity, timestamp, progname, msg)
				#"#{timestamp.strftime("%Y/%m/%d %H:%M:%S")}: #{severity} - #{msg}\n"
				"#{msg}\n"
			end
		end
	end
end
